package com.wei.duowan.bbs.ui.adapter;

import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;

import com.wei.duowan.bbs.App;
import com.wei.duowan.bbs.R;
import com.wei.duowan.bbs.model.NewsBean;
import com.wei.duowan.bbs.model.NewsDetailBean;
import com.wei.duowan.bbs.model.NewsTypeBean;
import com.wei.duowan.bbs.ui.activity.BaseActivity;
import com.wei.duowan.bbs.ui.activity.NewsActivity;
import com.wei.duowan.bbs.ui.activity.PictureActivity;
import com.wei.duowan.bbs.utils.TimeUtils;

/**
 * 作者：赵若位
 * 时间：2019/9/3 14:29
 * 联系方式：1070138445
 * 功能：
 */
public class NewsAdapter extends BaseDelegateAdapter<NewsBean>
{
    public NewsAdapter(AppCompatActivity activity)
    {
        super(activity, R.layout.layout_news);
    }


    @Override
    protected void convert(@Nullable BaseViewHolder holder, int position, @Nullable final NewsBean data)
    {
        holder.setVisibility(R.id.tv_count, NewsTypeBean.ADVERTISING == data.getShowType() ? View.GONE : View.VISIBLE)
                .setVisibility(R.id.img_game, NewsTypeBean.ARTICLE_NO_PICTURE == data.getShowType() ? View.GONE : (TextUtils.isEmpty(data.getPictureUrl())&&TextUtils.isEmpty(data.getAdSrc())) ? View.GONE : View.VISIBLE)
                .setVisibility(R.id.img_video, NewsTypeBean.VIDEO == data.getShowType() ? (TextUtils.isEmpty(data.getPictureUrl())) ? View.GONE : View.VISIBLE : View.GONE)
                .setText(R.id.tv_title, data.getTitle())
                .setText(R.id.tv_time, NewsTypeBean.ADVERTISING == data.getShowType() ? App.getResource().getString(R.string.advertising) : TimeUtils.getNewsListTime(data.getPublishTime()))
                .setText(R.id.tv_count, data.getComment())
                .setImageResource(R.id.img_game, NewsTypeBean.ADVERTISING == data.getShowType() ? data.getAdSrc() : data.getPictureUrl())
                .itemView.setOnClickListener(view ->
        {
//                ((BaseActivity) mActivity).alert("ShowType:" + data.getShowType());
//                ((BaseActivity) mActivity).openActivity(NewsActivity.class,data);
            ((BaseActivity) mActivity).openActivity(PictureActivity.class,data);
        });
    }
}
